package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.StrategyDetail;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IStrategyDetailService;
import cn.wolfcode.trip.base.service.IStrategyService;
import cn.wolfcode.trip.base.util.JSONResult;
import cn.wolfcode.trip.base.util.SevenUploadUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

@Controller
@RequestMapping("/strategyDetail")
public class StrategyDetailController {
    @Autowired
    private IStrategyDetailService strategyDetailService;
    @Autowired
    private IStrategyService strategyService;
    //待发布状态的游记管理
    @RequestMapping("/list")
    public String list(@ModelAttribute("qo")QueryObject qo, Model model){
        model.addAttribute("result",strategyDetailService.query(qo));
        model.addAttribute("strategys",strategyService.list());
        return "strategyDetail/list";
    }
    //保存或者修改推荐游记
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(StrategyDetail strategyDetail, MultipartFile file){
        JSONResult jsonResult = new JSONResult();
        try {
            //保存照片
            if (file !=null && file.getSize()>0){
                String filePath = SevenUploadUtil.uploadQiniu(file);
                strategyDetail.setCoverUrl(filePath);
            }
            strategyDetailService.saveOrUpdate(strategyDetail);
        }catch (Exception e){
            jsonResult.setMsg(e.getMessage());
        }
        return jsonResult;
    }
    //保存或者修改推荐游记
    @RequestMapping("/getContentByStrategyDetailId")
    @ResponseBody
    public Object getContentByStrategyDetailId(Long detailId){
        return strategyService.getContentByStrategyDetailId(detailId);
    }

}
